//
//  SADataShareViewController.m
//  SunOn
//
//  Created by RazeenCheng on 2017/5/2.
//  Copyright © 2017年 NeoZhang. All rights reserved.
//

#import "SADataShareViewController.h"
#import "SADataShareSectionHeaderCell.h"
#import "SADataShareListTableViewCell.h"
#import "SAShareListViewController.h"

@interface SADataShareViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong) NSMutableArray *dataArray;


@end

@implementation SADataShareViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.title = @"圣奥研发中心";
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView.dataSource = self;
    self.tableView.delegate = self;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 2) {
        return 2;
    }
    
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    if (row == 0) {
        SADataShareSectionHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SADataShareSectionHeaderCell" forIndexPath:indexPath];
        [cell configCellWithSection:section];
        return cell;
    } else {
        SADataShareListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SADataShareListTableViewCell" forIndexPath:indexPath];
        [cell configCellWithIndexPath:indexPath];
        
        __weak typeof(self) weakSelf = self;
        cell.detailAction = ^(NSInteger leftOrRight) {
            [weakSelf goToDetailViewControllerWithIndexPath:indexPath withLeftOrRight:leftOrRight];
        };
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger section = indexPath.section;
    NSInteger row = indexPath.row;
    
    if (row == 0) {
        return 70;
    } else {
        return 90;
    }
}


- (void)goToDetailViewControllerWithIndexPath:(NSIndexPath *)indexPath withLeftOrRight:(NSInteger)leftOrRight
{
    NSLog(@"(%ld,%ld)-%ld",indexPath.section,indexPath.row,leftOrRight);
    
    SAShareListViewController *shareListVC = [self.storyboard instantiateViewControllerWithIdentifier:@"SAShareListViewController"];
    [self.navigationController pushViewController:shareListVC animated:YES];
}

@end
